package com.ckzp.jfinal.weixin.impl;


import com.alibaba.fastjson.JSON;
import com.ckzp.core.json.Jmode;
import com.ckzp.jfinal.weixin.util.WxUserUtil;
import com.ckzp.weixin.service.MessageAction;
import com.ckzp.weixin.service.ServiceRequest;
import com.ckzp.weixin.service.ServiceResponse;
import com.ckzp.weixin.service.response.TextResponse;


import java.util.Date;
import java.util.Map;

/**
 * 用户关注了公众号执行事件
 * Created by 51594 on 2023/4/3.
 */
public class EventSubscribeAction implements MessageAction {
    /**
     * @param request
     * @return
     */
    public ServiceResponse doAction(ServiceRequest request) {
        if (request != null) {
            String wx_openid = request.getFromUserName();
            int mem_id = WxUserUtil.n().updateUserInfo(wx_openid);
            Jmode jmode = JSON.parseObject(request.getEventKey(), Jmode.class);
            TextResponse response = TextResponse.init(request);
            if ("substribe".equals(jmode.getStr("type"))) {
                response.setContent("感谢您的关注，扫码登陆成功");
            } else {
                response.setContent(request.getEventKey() + "---" + jmode.toJson());
            }
            return response;
        }
        return null;
    }
}
